package com.demo.spring.controller;


import com.demo.spring.framework.annotation.GPAutowired;
import com.demo.spring.framework.annotation.GPController;
import com.demo.spring.framework.annotation.GPRequestMapping;
import com.demo.spring.framework.annotation.GPRequestParam;
import com.demo.spring.service.IDemoService;
import com.demo.spring.service.impl.DemoService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//虽然，用法一样，但是没有功能
@GPController
@GPRequestMapping("/demo")
public class DemoController {

    @GPAutowired private IDemoService demoService;

    @GPRequestMapping("/query")
    public void query(HttpServletRequest req, HttpServletResponse resp,
                      @GPRequestParam("name") String name){
//		String result = demoService.get(name);
        String result = "My name is " + name;
        try {
            resp.getWriter().write(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @GPRequestMapping("/add")
    public void add(HttpServletRequest req, HttpServletResponse resp,
                    @GPRequestParam("a") Integer a, @GPRequestParam("b") Integer b){
        try {
            resp.getWriter().write(a + "+" + b + "=" + (a + b));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @GPRequestMapping("/sub")
    public void add(HttpServletRequest req, HttpServletResponse resp,
                    @GPRequestParam("a") Double a, @GPRequestParam("b") Double b){
        try {
            resp.getWriter().write(a + "-" + b + "=" + (a - b));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @GPRequestMapping("/remove")
    public String  remove(@GPRequestParam("id") Integer id){
        return "" + id;
    }

}
